#include <stdio.h>
#include <math.h>

#define VOLUME_SCORE (4.0f / 3.0f)
#define CAL_FIVE(value) (3 * (value * value * value * value * value) \
                        + 2 * (value * value * value * value)        \
                        - 5 * (value * value * value)                \
                        - (value * value) + 7 * value - 6)
#define CAL_SIX(x) (((((3 * x + 2) * x - 5) * x - 1) * x + 7) * x - 6)
float calVolume(float r) {
    return VOLUME_SCORE * M_PI * r * r * r;
}

void calSeven(int dollar);

int main(void) {
    printf("---------------编程题--------------\n");
    float amountLoad = 20000;
    float interest = 0.06f;
    float monthlyPayment = 386.66f;

    float monthlyInterest = interest / 12.0f;
    float curLoad = amountLoad;
    for (int i = 0; i < 3; ++i) {
        float tempLoad = curLoad - monthlyPayment;
        curLoad = tempLoad + monthlyInterest * curLoad;
        printf("Balance remaining after month %d: $%.2f\n", i + 1, curLoad);
    }
    printf("第八题->\n");
    // 月利率 0.0005，
    printf("第七题->\n");
    calSeven(93);
    printf("第六题->\n");
    printf("answer->%.2f \n", CAL_SIX(3.0f));
    printf("第五题->\n");
    printf("answer->%.2f \n", CAL_FIVE(3.0f));
    printf("第四题->\n");
    printf("Enter an amount: ");
    float amount;
    scanf("%f", &amount);
    // 这里有个问题，如果不用 %.2f而是用%f，输出的是 $104.999992~
    printf("With tax added: $%.2f\n", amount * 1.05f);
    printf("第二题、第三题->\n");
    float radius;
    printf("input radius: ");
    scanf("%f", &radius);
    printf("calculate is:%f \n", calVolume(radius));
    printf("---------------练习题----------------\n");
    // 跳过一些练习题
    // 第五题
    // 我目测 a,不合法，其他的都合法
//    int 100_bottles; // 这个报错了，先注掉
    int _100_bottles;
    int one__hundred__bottles;
    int bottles_by_the_hundred_;
    // 第4题 没有规律，int值会不一样，但是浮点数是固定的 0.000000
    int a;
    int b;
    float c;
    float d;
    int e;
    int f;
    int g;
    printf("%d, %d, %f, %f, %d, %d, %f\n", a, b, c, d, e, f, g);

    // 2.2 节 指令是 #include <stdio.h>,其他的都是语句
    printf("Parkinson's Law:\nWork expands so as to ");
    printf("fill the time\n");
    printf("available for its completion.\n");
    return 0;
}

void calSeven(int dollar) {
    int twentyDollars = 0, tenDollars = 0
            , fiveDollars = 0, oneDollar = 0;
    int curDollar = dollar;
    if(curDollar / 20 > 0) {
        twentyDollars = curDollar / 20;
        printf("$20 bills: %d\n", twentyDollars);
        curDollar = dollar % 20;
    } else {
        printf("$20 bills: %d\n", 0);
    }
    if(curDollar / 10 > 0) {
        tenDollars = curDollar / 10;
        printf("$10 bills: %d\n", tenDollars);
        curDollar = curDollar % 10;
    } else {
        printf("$10 bills: %d\n", 0);
    }
    if(curDollar / 10 > 0) {
        fiveDollars = curDollar / 5;
        printf(" $5 bills: %d\n", fiveDollars);
        curDollar = curDollar % 5;
    } else {
        printf(" $5 bills: %d\n", fiveDollars);
    }

    oneDollar = curDollar;
    printf(" $1 bills: %d\n", oneDollar);
}